﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace ArsenalManagement.Models
{
    public partial class ArsenalManagementContext : DbContext
    {
        public ArsenalManagementContext()
        {
        }

        public ArsenalManagementContext(DbContextOptions<ArsenalManagementContext> options)
            : base(options)
        {
        }

        public virtual DbSet<User> Users { get; set; } = null!;
        public virtual DbSet<Userinfo> Userinfos { get; set; } = null!;
        public virtual DbSet<Vehicle> Vehicles { get; set; } = null!;
        public virtual DbSet<Vessel> Vessels { get; set; } = null!;
        public virtual DbSet<Weapon> Weapons { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=106.54.168.84;Initial Catalog=ArsenalManagement;Persist Security Info=True;User ID=sa;Password=SHZ20010425cba;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>(entity =>
            {
                entity.ToTable("user");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Authority)
                    .HasColumnName("authority")
                    .HasComment("0是军官，1是士兵");

                entity.Property(e => e.Password)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("password");

                entity.Property(e => e.Username)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("username");
            });

            modelBuilder.Entity<Userinfo>(entity =>
            {
                entity.ToTable("userinfo");

                entity.Property(e => e.Id)
                    .ValueGeneratedNever()
                    .HasColumnName("id");

                entity.Property(e => e.Primaryweapon).HasColumnName("primaryweapon");

                entity.Property(e => e.Userid).HasColumnName("userid");

                entity.Property(e => e.Vehicle).HasColumnName("vehicle");

                entity.Property(e => e.Vessel).HasColumnName("vessel");

                entity.HasOne(d => d.PrimaryweaponNavigation)
                    .WithMany(p => p.Userinfos)
                    .HasForeignKey(d => d.Primaryweapon)
                    .OnDelete(DeleteBehavior.SetNull)
                    .HasConstraintName("FK__userinfo__primar__22751F6C");

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Userinfos)
                    .HasForeignKey(d => d.Userid)
                    .OnDelete(DeleteBehavior.Cascade)
                    .HasConstraintName("FK__userinfo__userid__236943A5");

                entity.HasOne(d => d.VehicleNavigation)
                    .WithMany(p => p.Userinfos)
                    .HasForeignKey(d => d.Vehicle)
                    .OnDelete(DeleteBehavior.SetNull)
                    .HasConstraintName("FK__userinfo__vehicl__245D67DE");

                entity.HasOne(d => d.VesselNavigation)
                    .WithMany(p => p.Userinfos)
                    .HasForeignKey(d => d.Vessel)
                    .OnDelete(DeleteBehavior.SetNull)
                    .HasConstraintName("FK__userinfo__vessel__25518C17");
            });

            modelBuilder.Entity<Vehicle>(entity =>
            {
                entity.ToTable("vehicle");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.ImgUrl)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("img_url");

                entity.Property(e => e.Info)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("info");

                entity.Property(e => e.Vehiclename)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("vehiclename");
            });

            modelBuilder.Entity<Vessel>(entity =>
            {
                entity.ToTable("vessel");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.ImgUrl)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("img_url");

                entity.Property(e => e.Info)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("info");

                entity.Property(e => e.Vesselname)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("vesselname");
            });

            modelBuilder.Entity<Weapon>(entity =>
            {
                entity.ToTable("weapon");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.ImgUrl)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("img_url");

                entity.Property(e => e.Info)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("info");

                entity.Property(e => e.Weaponname)
                    .HasMaxLength(255)
                    .IsUnicode(false)
                    .HasColumnName("weaponname");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
